<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title></title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <link href="/public/bootstrap3/css/style.css" rel="stylesheet">
    <link href="/public/bootstrap3/css/style-responsive.css" rel="stylesheet">
    <link href="/public/css/util/util-form.css" rel="stylesheet">
    <style type="text/css">

    </style>
</head>
<body class="sticky-header">
<div class="row">
    <div class="col-xs-12">
        <section class="panel">
            <div class="panel-heading">
                <div align="center">新增模型</div>
            </div>
            <div class="panel-body ops-global-panel">
                <form class="form-horizontal tasi-form ops-global-form" id="modelForm" method="post">
                    <div class="form-group col-xs-6">
                        <label class="col-xs-4 control-label">模型标题</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="modelName" name="modelName" value="">
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-4 control-label">模型分类</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="category" name="category" value="">
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-4 control-label">模型描述</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="description" name="description" value="">
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-4 control-label">流程名称</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="name" name="name" value="">
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-4 control-label">流程标识</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="processId" name="processId" value="">
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-4 control-label">流程作者</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="processUser" name="processUser" value="">
                        </div>
                    </div>
                    <!-- 线条-误删 -->
                    <div class="form-group col-xs-12">
                    </div>
                </form>
            </div>
            <div class="col-xs-12 ops-global-submit">
                <button class="btn btn-success col-xs-offset-3 col-xs-2" type="button" id = "modelSave">保存</button>
                <button class="btn btn-default col-xs-offset-2 col-xs-2" type="button" id = "modelCancle">取消</button>
            </div>
        </section>
    </div>
</div>
</body>
<script src="/public/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="public/js/jquery.tips.js"></script>
<script>
    $(function(){
        var frameIndex = parent.layer.getFrameIndex(window.name);
        $('#modelSave').click(function(){

            if(!validateModel()){
                return;
            }
            var formAction = '/workflow/model/add';
            $.ajax({
                type:"post",
                url:formAction,
                dataType:"json",
                data : $('#modelForm').serialize(),
                success:function(data){
                    if(data.resCode == '200'){
                        parent.layer.msg(data.resMessage,{time:1200});
                        parent.$("#modelTable").bootstrapTable('refresh',{silent: true});
                        parent.setModelId(data.resData);
                        parent.layer.close(frameIndex);
                        return true;
                    }else {
                        parent.layer.close(frameIndex);
                        parent.layer.msg(data.resMessage);
                        return false;
                    }
                },
                error:function(data){
                    parent.layer.msg("未知错误");
                }
            })
        });
        $('#modelCancle').click(function(){
            parent.layer.msg('用户已取消', {
                time: 1200 //20s后自动关闭
            });
            parent.layer.close(frameIndex);
        })
    })

    /**
     * 校验入参
     */
    function validateModel(){

        var isOk = true;
        if($("#modelName").val()=="") {
            $("#modelName").tips({
                side: 3,
                msg: '请输入模型标题',
                bg: '#AE81FF',
                time: 2
            });
            $("#modelName").focus();
            isOk = false;
        }
        if($("#category").val()=="") {
            $("#category").tips({
                side: 3,
                msg: '请输入模型分类',
                bg: '#AE81FF',
                time: 2
            });
            $("#category").focus();
            isOk = false;
        }
        if($("#description").val()=="") {
            $("#description").tips({
                side: 3,
                msg: '请输入模型描述',
                bg: '#AE81FF',
                time: 2
            });
            $("#description").focus();
            isOk = false;
        }
        if($("#name").val()=="") {
            $("#name").tips({
                side: 3,
                msg: '请输入流程名称',
                bg: '#AE81FF',
                time: 2
            });
            $("#name").focus();
            isOk = false;
        }
        if($("#processId").val()=="") {
            $("#processId").tips({
                side: 3,
                msg: '请输入流程标识',
                bg: '#AE81FF',
                time: 2
            });
            $("#processId").focus();
            isOk = false;
        }
        if($("#processUser").val()=="") {
            $("#processUser").tips({
                side: 3,
                msg: '请输入流程作者',
                bg: '#AE81FF',
                time: 2
            });
            $("#processUser").focus();
            isOk = false;
        }
        return isOk;
    }
</script>
</html>